package com.rd.student.dashuju.wangbo.demo4;


import com.sun.istack.internal.NotNull;

import java.util.concurrent.locks.ReentrantLock;

public class TestBank01 extends Thread{
    Account account;
    Double money;

    public TestBank01(@NotNull String name, Account account, Double money) {
        super(name);
        this.account = account;
        this.money = money;
    }

    @Override
    public void run() {
        synchronized (account){
            if (account.balance < money) {
                System.out.println("余额不足");
                return;
            }
            System.out.println(getName() + "可以取钱");
            account.balance = account.balance - money;
            System.out.println("取钱后的余额为：" + account.balance);
        }


    }

    public static void main(String[] args) {
        Account account = new Account("123456", 888);
        new TestBank01("zhangsan", account, 666.6).start();
        new TestBank01("lisi", account, 666.6).start();

    }
}

